<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>珠峰架构师成长计划</title>
    <link rel="stylesheet" type="text/css" href="../static/css/main.css">
</head>
<body>
<div class="nav">
    <div class="logo">
        
            珠峰架构师成长计划
        
    </div>
<ul><li><a href="../index.html">0.Async</a></li><li><a href="../html/0.editor.html">0.editor</a></li><li><a href="../html/0.module.html">0.module</a></li><li><a href="../html/1.ES2015.html">1.ES2015</a></li><li><a href="../html/2.Promise.html">2.Promise</a></li><li><a href="../html/3.Node.html">3.Node</a></li><li><a href="../html/4.NodeInstall.html">4.NodeInstall</a></li><li><a href="../html/5.REPL.html">5.REPL</a></li><li><a href="../html/6.NodeCore.html">6.NodeCore</a></li><li><a href="../html/7.module&NPM.html">7.module&NPM</a></li><li><a href="../html/8.Encoding.html">8.Encoding</a></li><li><a href="../html/9.Buffer.html">9.Buffer</a></li><li><a href="../html/10.fs.html">10.fs</a></li><li><a href="../html/11.Stream-1.html">11.Stream-1</a></li><li><a href="../html/11.Stream-2.html">11.Stream-2</a></li><li><a href="../html/11.Stream-3.html">11.Stream-3</a></li><li><a href="../html/11.Stream-4.html">11.Stream-4</a></li><li><a href="../html/12-Network-2.html">12-Network-2</a></li><li><a href="../html/12.NetWork-3.html">12.NetWork-3</a></li><li><a href="../html/12.Network-1.html">12.Network-1</a></li><li><a href="../html/13.tcp.html">13.tcp</a></li><li><a href="../html/14.http-1.html">14.http-1</a></li><li><a href="../html/14.http-2.html">14.http-2</a></li><li><a href="../html/15.compress.html">15.compress</a></li><li><a href="../html/16.crypto.html">16.crypto</a></li><li><a href="../html/17.process.html">17.process</a></li><li><a href="../html/18.yargs.html">18.yargs</a></li><li><a href="../html/19.cache.html">19.cache</a></li><li><a href="../html/20.action.html">20.action</a></li><li><a href="../html/21.https.html">21.https</a></li><li><a href="../html/22.cookie.html">22.cookie</a></li><li><a href="../html/23.session.html">23.session</a></li><li><a href="../html/24.express-1.html">24.express-1</a></li><li><a href="../html/24.express-2.html">24.express-2</a></li><li><a href="../html/24.express-3.html">24.express-3</a></li><li><a href="../html/24.express-4.html">24.express-4</a></li><li><a href="../html/25.koa-1.html">25.koa-1</a></li><li><a href="../html/26.webpack-1-basic.html">26.webpack-1-basic</a></li><li><a href="../html/26.webpack-2-optimize.html">26.webpack-2-optimize</a></li><li><a href="../html/26.webpack-3.tapable.html">26.webpack-3.tapable</a></li><li><a href="../html/26.webpack-4-AST.html">26.webpack-4-AST</a></li><li><a href="../html/26.webpack-5-source.html">26.webpack-5-source</a></li><li><a href="../html/26.webpack-6-loader.html">26.webpack-6-loader</a></li><li><a href="../html/26.webpack-7-plugin.html">26.webpack-7-plugin</a></li><li><a href="../html/26.webpack-8-hand.html">26.webpack-8-hand</a></li><li><a href="../html/27.react-1.html">27.react-1</a></li><li><a href="../html/27.react-2.html">27.react-2</a></li><li><a href="../html/27.react-3.html">27.react-3</a></li><li><a href="../html/27.react-4-immutable.html">27.react-4-immutable</a></li><li><a href="../html/27.react-5-react-dom-diff.html">27.react-5-react-dom-diff</a></li><li><a href="../html/27.react-6.html">27.react-6</a></li><li><a href="../html/28.react-mobx.html">28.react-mobx</a></li><li><a href="../html/28.redux-0.html">28.redux-0</a></li><li><a href="../html/28.redux-1.html">28.redux-1</a></li><li><a href="../html/28.redux-2-中间件.html">28.redux-2-中间件</a></li><li><a href="../html/28.redux-3-saga.html">28.redux-3-saga</a></li><li><a href="../html/28.redux-jwt-back.html">28.redux-jwt-back</a></li><li><a href="../html/28.redux-jwt-front.html">28.redux-jwt-front</a></li><li><a href="../html/29.mongodb-1.html">29.mongodb-1</a></li><li><a href="../html/29.mongodb-2.html">29.mongodb-2</a></li><li><a href="../html/29.mongodb-3.html">29.mongodb-3</a></li><li><a href="../html/29.mongodb-4.html">29.mongodb-4</a></li><li><a href="../html/29.mongodb-5.html">29.mongodb-5</a></li><li><a href="../html/29.mongodb-6.html">29.mongodb-6</a></li><li><a href="../html/30.cms-1-mysql.html">30.cms-1-mysql</a></li><li><a href="../html/30.cms-2-mysql.html">30.cms-2-mysql</a></li><li><a href="../html/30.cms-3-mysql.html">30.cms-3-mysql</a></li><li><a href="../html/30.cms-4-egg.html">30.cms-4-egg</a></li><li><a href="../html/30.cms-5-api.html">30.cms-5-api</a></li><li><a href="../html/30.cms-6-roadhog.html">30.cms-6-roadhog</a></li><li><a href="../html/30.cms-7-umi.html">30.cms-7-umi</a></li><li><a href="../html/30.cms-8-dva.html">30.cms-8-dva</a></li><li><a href="../html/30.cms-9-dva.html">30.cms-9-dva</a></li><li><a href="../html/30.cms-10-front.html">30.cms-10-front</a></li><li><a href="../html/30.cms-11-deploy.html">30.cms-11-deploy</a></li><li><a href="../html/33.redis.html">33.redis</a></li><li><a href="../html/34.unittest.html">34.unittest</a></li><li><a href="../html/35.jwt.html">35.jwt</a></li><li><a href="../html/36.websocket-1.html">36.websocket-1</a></li><li><a href="../html/36.websocket-2.html">36.websocket-2</a></li><li><a href="../html/38.chat-api-1.html">38.chat-api-1</a></li><li><a href="../html/38.chat-api-2.html">38.chat-api-2</a></li><li><a href="../html/38.chat-3.html">38.chat-3</a></li><li><a href="../html/38.chat-api-3.html">38.chat-api-3</a></li><li><a href="../html/38.chat.html">38.chat</a></li><li><a href="../html/38.chat2.html">38.chat2</a></li><li><a href="../html/38.chat2.html">38.chat2</a></li><li><a href="../html/39.crawl-0.html">39.crawl-0</a></li><li><a href="../html/39.crawl-1.html">39.crawl-1</a></li><li><a href="../html/39.crawl-2.html">39.crawl-2</a></li><li><a href="../html/40.deploy.html">40.deploy</a></li><li><a href="../html/41.safe.html">41.safe</a></li><li><a href="../html/42.test.html">42.test</a></li><li><a href="../html/43.nginx.html">43.nginx</a></li><li><a href="../html/44.enzyme.html">44.enzyme</a></li><li><a href="../html/45.docker.html">45.docker</a></li><li><a href="../html/46.elastic.html">46.elastic</a></li><li><a href="../html/47.oauth.html">47.oauth</a></li><li class="active"><a href="../html/48.wxpay.html">48.wxpay</a></li><li><a href="../html/49.nunjucks.html">49.nunjucks</a></li><li><a href="../html/50.ketang.html">50.ketang</a></li><li><a href="../html/index.html">index</a></li><li><a href="../html/51.typescript.html">51.typescript</a></li><li><a href="../html/52.UML.html">52.UML</a></li><li><a href="../html/53.design.html">53.design</a></li><li><a href="../html/index.html">index</a></li><li><a href="../html/54.linux.html">54.linux</a></li><li><a href="../html/55.yaml.html">55.yaml</a></li><li><a href="../html/50.ketang2.html">50.ketang2</a></li><li><a href="../html/56.ts.html">56.ts</a></li><li><a href="../html/57.ts_react.html">57.ts_react</a></li><li><a href="../html/58.react-ssr.html">58.react-ssr</a></li><li><a href="../html/59.react-ssr.html">59.react-ssr</a></li></ul></div>


<div class="warpper">

    <div class="page-toc">
        <ul><li><a href="#t01. 微信支付">1. 微信支付</a></li><li><a href="#t12. 申请流程">2. 申请流程</a><ul><li><a href="#t22.1 注册公众号">2.1 注册公众号</a></li><li><a href="#t32.2 认证公众号">2.2 认证公众号</a></li><li><a href="#t42.3 提交资料申请微信支付">2.3 提交资料申请微信支付</a></li><li><a href="#t52.4  开户成功，进行账户验证">2.4  开户成功，进行账户验证</a></li><li><a href="#t62.5  在线签署协议">2.5  在线签署协议</a></li><li><a href="#t72.6  启动设计和开发">2.6  启动设计和开发</a></li></ul></li><li><a href="#t83. 准备素材">3. 准备素材</a></li><li><a href="#t94.接入流程">4.接入流程</a></li><li><a href="#t105.绘制页面">5.绘制页面</a><ul><li><a href="#t115.1 生成项目">5.1 生成项目</a></li><li><a href="#t125.2 支持模版">5.2 支持模版</a><ul><li><a href="#t135.2.1 package.json">5.2.1 package.json</a></li><li><a href="#t145.2.2 app/controller/home.js">5.2.2 app/controller/home.js</a></li><li><a href="#t155.2.3 checkout.html">5.2.3 checkout.html</a></li><li><a href="#t165.2.4 config.default.js">5.2.4 config.default.js</a></li><li><a href="#t175.2.5 plugin.js">5.2.5 plugin.js</a></li></ul></li><li><a href="#t185.3 支付和通知">5.3 支付和通知</a><ul><li><a href="#t195.3.1 package.json">5.3.1 package.json</a></li><li><a href="#t205.3.2 app/router.js">5.3.2 app/router.js</a></li><li><a href="#t215.3.3 home.js">5.3.3 home.js</a></li><li><a href="#t225.3.4 checkout.html">5.3.4 checkout.html</a></li><li><a href="#t235.3.5 config.default.js">5.3.5 config.default.js</a></li></ul></li><li><a href="#t245.4 查询结果">5.4 查询结果</a><ul><li><a href="#t255.4.1 app/router.js">5.4.1 app/router.js</a></li><li><a href="#t265.4.2 result.html">5.4.2 result.html</a></li><li><a href="#t275.4.3 config.default.js">5.4.3 config.default.js</a></li><li><a href="#t285.4.4 app/controller/home.js">5.4.4 app/controller/home.js</a></li></ul></li></ul></li><li><a href="#t29参考资料">参考资料</a></li></ul>
    </div>
    
    <div class="content markdown-body">
        <h2 id="t01. &#x5FAE;&#x4FE1;&#x652F;&#x4ED8;">1. &#x5FAE;&#x4FE1;&#x652F;&#x4ED8; <a href="#t01. &#x5FAE;&#x4FE1;&#x652F;&#x4ED8;"> # </a></h2>
<ul>
<li>&#x626B;&#x7801;&#x652F;&#x4ED8;&#x662F;&#x6307;&#x5546;&#x6237;&#x7CFB;&#x7EDF;&#x6309;&#x5FAE;&#x4FE1;&#x652F;&#x4ED8;&#x534F;&#x8BAE;&#x751F;&#x6210;&#x652F;&#x4ED8;&#x4E8C;&#x7EF4;&#x7801;&#xFF0C;&#x7528;&#x6237;&#x518D;&#x7528;&#x5FAE;&#x4FE1;&#x201C;&#x626B;&#x4E00;&#x626B;&#x201D;&#x6765;&#x5B8C;&#x6210;&#x652F;&#x4ED8;&#x3002;</li>
<li>&#x9002;&#x7528;&#x4E8E;PC&#x7F51;&#x7AD9;&#x652F;&#x4ED8;&#x3001;&#x5B9E;&#x4F53;&#x5E97;&#x5355;&#x54C1;&#x7B49;&#x573A;&#x666F;&#x3002;</li>
</ul>
<p><img src="http://file.service.qq.com/user-files/uploads/201808/8f41fd93e1f52c38fbd067b9d09f11ed.jpg" alt="qcode"></p>
<h2 id="t12. &#x7533;&#x8BF7;&#x6D41;&#x7A0B;">2. &#x7533;&#x8BF7;&#x6D41;&#x7A0B; <a href="#t12. &#x7533;&#x8BF7;&#x6D41;&#x7A0B;"> # </a></h2>
<h3 id="t22.1 &#x6CE8;&#x518C;&#x516C;&#x4F17;&#x53F7;">2.1 &#x6CE8;&#x518C;&#x516C;&#x4F17;&#x53F7; <a href="#t22.1 &#x6CE8;&#x518C;&#x516C;&#x4F17;&#x53F7;"> # </a></h3>
<p>&#x8BF7;&#x6839;&#x636E;&#x8425;&#x4E1A;&#x6267;&#x7167;&#x7C7B;&#x578B;&#x9009;&#x62E9;&#x4EE5;&#x4E0B;&#x4E3B;&#x4F53;&#x6CE8;&#x518C;&#xFF1A;</p>
<ul>
<li><a href="http://kf.qq.com/faq/120911VrYVrA151009JB3i2Q.html">&#x4E2A;&#x4F53;&#x5DE5;&#x5546;&#x6237;</a></li>
<li><a href="http://kf.qq.com/faq/120911VrYVrA151013MfYvYV.html">&#x4F01;&#x4E1A;/&#x516C;&#x53F8;</a></li>
<li><a href="http://kf.qq.com/faq/120911VrYVrA15100973ABZz.html">&#x653F;&#x5E9C;</a></li>
<li><a href="http://kf.qq.com/faq/120911VrYVrA151013aMNfeQ.html">&#x5A92;&#x4F53;</a></li>
<li><a href="http://kf.qq.com/faq/120911VrYVrA151013nYFZ7Z.html">&#x5176;&#x4ED6;&#x7C7B;&#x578B;</a>|</li>
</ul>
<h3 id="t32.2 &#x8BA4;&#x8BC1;&#x516C;&#x4F17;&#x53F7;">2.2 &#x8BA4;&#x8BC1;&#x516C;&#x4F17;&#x53F7; <a href="#t32.2 &#x8BA4;&#x8BC1;&#x516C;&#x4F17;&#x53F7;"> # </a></h3>
<p>&#x516C;&#x4F17;&#x53F7;&#x8BA4;&#x8BC1;&#x540E;&#x624D;&#x53EF;&#x7533;&#x8BF7;&#x5FAE;&#x4FE1;&#x652F;&#x4ED8;&#xFF0C;&#x8BA4;&#x8BC1;&#x8D39;&#xFF1A;300&#x5143;/&#x6B21;
&#x67E5;&#x770B;<a href="http://kf.qq.com/product/weixinmp.html#hid=97">&#x8BA4;&#x8BC1;&#x6D41;&#x7A0B;</a></p>
<h3 id="t42.3 &#x63D0;&#x4EA4;&#x8D44;&#x6599;&#x7533;&#x8BF7;&#x5FAE;&#x4FE1;&#x652F;&#x4ED8;">2.3 &#x63D0;&#x4EA4;&#x8D44;&#x6599;&#x7533;&#x8BF7;&#x5FAE;&#x4FE1;&#x652F;&#x4ED8; <a href="#t42.3 &#x63D0;&#x4EA4;&#x8D44;&#x6599;&#x7533;&#x8BF7;&#x5FAE;&#x4FE1;&#x652F;&#x4ED8;"> # </a></h3>
<p>&#x767B;&#x5F55;&#x516C;&#x4F17;&#x5E73;&#x53F0;&#xFF0C;&#x70B9;&#x51FB;&#x5DE6;&#x4FA7;&#x83DC;&#x5355;&#x3010;&#x5FAE;&#x4FE1;&#x652F;&#x4ED8;&#x3011;&#xFF0C;&#x5F00;&#x59CB;&#x586B;&#x5199;&#x8D44;&#x6599;&#x7B49;&#x5F85;&#x5BA1;&#x6838;&#xFF0C;&#x5BA1;&#x6838;&#x65F6;&#x95F4;&#x4E3A;48&#x5C0F;&#x65F6;&#x5185;&#x3002;</p>
<h3 id="t52.4  &#x5F00;&#x6237;&#x6210;&#x529F;&#xFF0C;&#x8FDB;&#x884C;&#x8D26;&#x6237;&#x9A8C;&#x8BC1;">2.4  &#x5F00;&#x6237;&#x6210;&#x529F;&#xFF0C;&#x8FDB;&#x884C;&#x8D26;&#x6237;&#x9A8C;&#x8BC1; <a href="#t52.4  &#x5F00;&#x6237;&#x6210;&#x529F;&#xFF0C;&#x8FDB;&#x884C;&#x8D26;&#x6237;&#x9A8C;&#x8BC1;"> # </a></h3>
<p>&#x8D44;&#x6599;&#x5BA1;&#x6838;&#x901A;&#x8FC7;&#x540E;&#xFF0C;&#x5F00;&#x6237;&#x4FE1;&#x606F;&#x4F1A;&#x901A;&#x8FC7;&#x90AE;&#x4EF6;&#x3001;&#x516C;&#x4F17;&#x53F7;&#x53D1;&#x9001;&#x7ED9;&#x8054;&#x7CFB;&#x4EBA;&#xFF0C;&#x8BF7;&#x6309;&#x7167;&#x6307;&#x5F15;&#x586B;&#x5199;&#x8D22;&#x4ED8;&#x901A;&#x5907;&#x4ED8;&#x91D1;&#x6C47;&#x5165;&#x7684;&#x968F;&#x673A;&#x91D1;&#x989D;&#xFF0C;&#x5B8C;&#x6210;&#x8D26;&#x6237;&#x9A8C;&#x8BC1;&#x3002;&#xFF08;&#x67E5;&#x770B;&#x9A8C;&#x8BC1;&#x65B9;&#x6CD5;&#xFF09;</p>
<h3 id="t62.5  &#x5728;&#x7EBF;&#x7B7E;&#x7F72;&#x534F;&#x8BAE;">2.5  &#x5728;&#x7EBF;&#x7B7E;&#x7F72;&#x534F;&#x8BAE; <a href="#t62.5  &#x5728;&#x7EBF;&#x7B7E;&#x7F72;&#x534F;&#x8BAE;"> # </a></h3>
<p>&#x672C;&#x534F;&#x8BAE;&#x4E3A;&#x7EBF;&#x4E0A;&#x7535;&#x5B50;&#x534F;&#x8BAE;&#xFF0C;&#x7B7E;&#x7F72;&#x540E;&#x65B9;&#x53EF;&#x8FDB;&#x884C;&#x4EA4;&#x6613;&#x53CA;&#x8D44;&#x91D1;&#x7ED3;&#x7B97;&#xFF0C;&#x7B7E;&#x7F72;&#x5B8C;&#x7ACB;&#x5373;&#x751F;&#x6548;&#x3002;&#x70B9;&#x6B64;&#x63D0;&#x524D;&#x9884;&#x89C8;&#x534F;&#x8BAE;&#x5185;&#x5BB9;&#x3002;</p>
<h3 id="t72.6  &#x542F;&#x52A8;&#x8BBE;&#x8BA1;&#x548C;&#x5F00;&#x53D1;">2.6  &#x542F;&#x52A8;&#x8BBE;&#x8BA1;&#x548C;&#x5F00;&#x53D1; <a href="#t72.6  &#x542F;&#x52A8;&#x8BBE;&#x8BA1;&#x548C;&#x5F00;&#x53D1;"> # </a></h3>
<p>&#x652F;&#x4ED8;&#x63A5;&#x53E3;&#x5DF2;&#x83B7;&#x5F97;&#xFF0C;&#x53EF;&#x6839;&#x636E;<a href="https://pay.weixin.qq.com/wiki/doc/api/index.html">&#x5F00;&#x53D1;&#x6587;&#x6863;</a>&#x8FDB;&#x884C;&#x5F00;&#x53D1;&#xFF0C;&#x4E5F;&#x53EF;&#x4E86;&#x89E3;&#x6210;&#x529F;&#x6848;&#x4F8B;&#x754C;&#x9762;&#x793A;&#x610F;&#x53CA;&#x7D20;&#x6750;&#x3002;</p>
<h2 id="t83. &#x51C6;&#x5907;&#x7D20;&#x6750;">3. &#x51C6;&#x5907;&#x7D20;&#x6750; <a href="#t83. &#x51C6;&#x5907;&#x7D20;&#x6750;"> # </a></h2>
<ul>
<li><a href="https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=6_1">&#x626B;&#x7801;&#x652F;&#x4ED8;</a></li>
<li>APPID <a href="https://mp.weixin.qq.com">&#x516C;&#x4F17;&#x5E73;&#x53F0;</a>(1959583119)-&gt;&#x53F3;&#x4E0A;&#x89D2;-&gt;&#x5F00;&#x53D1;&#x8005;ID-&gt;AppID</li>
<li>&#x5546;&#x6237;&#x53F7;&#x7801;&#x548C;&#x914D;&#x7F6E;&#x56DE;&#x8C03;&#x94FE;&#x63A5; <a href="https://pay.weixin.qq.com">&#x5546;&#x6237;&#x5E73;&#x53F0;</a>-&gt;&#x4EA7;&#x54C1;&#x4E2D;&#x5FC3;-&gt;&#x5F00;&#x53D1;&#x914D;&#x7F6E;-&gt;&#x5546;&#x6237;&#x4FE1;&#x606F;-&gt;&#x5546;&#x6237;&#x53F7;</li>
<li>&#x914D;&#x7F6E;APPID <a href="https://pay.weixin.qq.com">&#x5546;&#x6237;&#x5E73;&#x53F0;</a>-&gt;&#x4EA7;&#x54C1;&#x4E2D;&#x5FC3;-&gt;APPID&#x6388;&#x6743;&#x7BA1;&#x7406;</li>
<li>API&#x5BC6;&#x94A5; <a href="https://pay.weixin.qq.com">&#x5546;&#x6237;&#x5E73;&#x53F0;</a>-&gt;&#x8D26;&#x6237;&#x4E2D;&#x5FC3;-&gt;API&#x5B89;&#x5168;-&gt;&#x8BBE;&#x7F6E;API&#x5BC6;&#x94A5;</li>
</ul>
<h2 id="t94.&#x63A5;&#x5165;&#x6D41;&#x7A0B;">4.&#x63A5;&#x5165;&#x6D41;&#x7A0B; <a href="#t94.&#x63A5;&#x5165;&#x6D41;&#x7A0B;"> # </a></h2>
<ul>
<li>&#x5546;&#x6237;&#x540E;&#x53F0;&#x7CFB;&#x7EDF;&#x5148;&#x8C03;&#x7528;&#x5FAE;&#x4FE1;&#x652F;&#x4ED8;&#x7684;&#x7EDF;&#x4E00;&#x4E0B;&#x5355;&#x63A5;&#x53E3;</li>
<li>&#x5FAE;&#x4FE1;&#x540E;&#x53F0;&#x7CFB;&#x7EDF;&#x8FD4;&#x56DE;&#x94FE;&#x63A5;&#x53C2;&#x6570;code_url</li>
<li>&#x5546;&#x6237;&#x540E;&#x53F0;&#x7CFB;&#x7EDF;&#x5C06;code_url&#x503C;&#x751F;&#x6210;&#x4E8C;&#x7EF4;&#x7801;&#x56FE;&#x7247;</li>
<li>&#x7528;&#x6237;&#x4F7F;&#x7528;&#x5FAE;&#x4FE1;&#x5BA2;&#x6237;&#x7AEF;&#x626B;&#x7801;&#x540E;&#x53D1;&#x8D77;&#x652F;&#x4ED8;</li>
<li>&#x6CE8;&#x610F;&#xFF1A;code_url&#x6709;&#x6548;&#x671F;&#x4E3A;2&#x5C0F;&#x65F6;&#xFF0C;&#x8FC7;&#x671F;&#x540E;&#x626B;&#x7801;&#x4E0D;&#x80FD;&#x518D;&#x53D1;&#x8D77;&#x652F;&#x4ED8;&#x3002;</li>
</ul>
<p><img src="https://pay.weixin.qq.com/wiki/doc/api/img/chapter6_5_1.png" alt="&#x63A5;&#x5165;&#x6D41;&#x7A0B;"></p>
<p>&#x4E1A;&#x52A1;&#x6D41;&#x7A0B;&#x8BF4;&#x660E;&#xFF1A;</p>
<ul>
<li>1&#xFF09;&#x5546;&#x6237;&#x540E;&#x53F0;&#x7CFB;&#x7EDF;&#x6839;&#x636E;&#x7528;&#x6237;&#x9009;&#x8D2D;&#x7684;&#x5546;&#x54C1;&#x751F;&#x6210;&#x8BA2;&#x5355;&#x3002;</li>
<li>2&#xFF09;&#x7528;&#x6237;&#x786E;&#x8BA4;&#x652F;&#x4ED8;&#x540E;&#x8C03;&#x7528;&#x5FAE;&#x4FE1;&#x652F;&#x4ED8;<a href="https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=9_1">&#x7EDF;&#x4E00;&#x4E0B;&#x5355;API</a>&#x751F;&#x6210;&#x9884;&#x652F;&#x4ED8;&#x4EA4;&#x6613;&#xFF1B;</li>
<li>3&#xFF09;&#x5FAE;&#x4FE1;&#x652F;&#x4ED8;&#x7CFB;&#x7EDF;&#x6536;&#x5230;&#x8BF7;&#x6C42;&#x540E;&#x751F;&#x6210;&#x9884;&#x652F;&#x4ED8;&#x4EA4;&#x6613;&#x5355;&#xFF0C;&#x5E76;&#x8FD4;&#x56DE;&#x4EA4;&#x6613;&#x4F1A;&#x8BDD;&#x7684;&#x4E8C;&#x7EF4;&#x7801;&#x94FE;&#x63A5;code_url&#x3002;</li>
<li>4&#xFF09;&#x5546;&#x6237;&#x540E;&#x53F0;&#x7CFB;&#x7EDF;&#x6839;&#x636E;&#x8FD4;&#x56DE;&#x7684;code_url&#x751F;&#x6210;&#x4E8C;&#x7EF4;&#x7801;&#x3002;</li>
<li>5&#xFF09;&#x7528;&#x6237;&#x6253;&#x5F00;&#x5FAE;&#x4FE1;&#x201C;&#x626B;&#x4E00;&#x626B;&#x201D;&#x626B;&#x63CF;&#x4E8C;&#x7EF4;&#x7801;&#xFF0C;&#x5FAE;&#x4FE1;&#x5BA2;&#x6237;&#x7AEF;&#x5C06;&#x626B;&#x7801;&#x5185;&#x5BB9;&#x53D1;&#x9001;&#x5230;&#x5FAE;&#x4FE1;&#x652F;&#x4ED8;&#x7CFB;&#x7EDF;&#x3002;</li>
<li>6&#xFF09;&#x5FAE;&#x4FE1;&#x652F;&#x4ED8;&#x7CFB;&#x7EDF;&#x6536;&#x5230;&#x5BA2;&#x6237;&#x7AEF;&#x8BF7;&#x6C42;&#xFF0C;&#x9A8C;&#x8BC1;&#x94FE;&#x63A5;&#x6709;&#x6548;&#x6027;&#x540E;&#x53D1;&#x8D77;&#x7528;&#x6237;&#x652F;&#x4ED8;&#xFF0C;&#x8981;&#x6C42;&#x7528;&#x6237;&#x6388;&#x6743;&#x3002;</li>
<li>7&#xFF09;&#x7528;&#x6237;&#x5728;&#x5FAE;&#x4FE1;&#x5BA2;&#x6237;&#x7AEF;&#x8F93;&#x5165;&#x5BC6;&#x7801;&#xFF0C;&#x786E;&#x8BA4;&#x652F;&#x4ED8;&#x540E;&#xFF0C;&#x5FAE;&#x4FE1;&#x5BA2;&#x6237;&#x7AEF;&#x63D0;&#x4EA4;&#x6388;&#x6743;&#x3002;</li>
<li>8&#xFF09;&#x5FAE;&#x4FE1;&#x652F;&#x4ED8;&#x7CFB;&#x7EDF;&#x6839;&#x636E;&#x7528;&#x6237;&#x6388;&#x6743;&#x5B8C;&#x6210;&#x652F;&#x4ED8;&#x4EA4;&#x6613;&#x3002;</li>
<li>9&#xFF09;&#x5FAE;&#x4FE1;&#x652F;&#x4ED8;&#x7CFB;&#x7EDF;&#x5B8C;&#x6210;&#x652F;&#x4ED8;&#x4EA4;&#x6613;&#x540E;&#x7ED9;&#x5FAE;&#x4FE1;&#x5BA2;&#x6237;&#x7AEF;&#x8FD4;&#x56DE;&#x4EA4;&#x6613;&#x7ED3;&#x679C;&#xFF0C;&#x5E76;&#x5C06;&#x4EA4;&#x6613;&#x7ED3;&#x679C;&#x901A;&#x8FC7;&#x77ED;&#x4FE1;&#x3001;&#x5FAE;&#x4FE1;&#x6D88;&#x606F;&#x63D0;&#x793A;&#x7528;&#x6237;&#x3002;&#x5FAE;&#x4FE1;&#x5BA2;&#x6237;&#x7AEF;&#x5C55;&#x793A;&#x652F;&#x4ED8;&#x4EA4;&#x6613;&#x7ED3;&#x679C;&#x9875;&#x9762;&#x3002;</li>
<li>10&#xFF09;&#x5FAE;&#x4FE1;&#x652F;&#x4ED8;&#x7CFB;&#x7EDF;&#x901A;&#x8FC7;&#x53D1;&#x9001;&#x5F02;&#x6B65;&#x6D88;&#x606F;&#x901A;&#x77E5;&#x5546;&#x6237;&#x540E;&#x53F0;&#x7CFB;&#x7EDF;&#x652F;&#x4ED8;&#x7ED3;&#x679C;&#x3002;&#x5546;&#x6237;&#x540E;&#x53F0;&#x7CFB;&#x7EDF;&#x9700;&#x56DE;&#x590D;&#x63A5;&#x6536;&#x60C5;&#x51B5;&#xFF0C;&#x901A;&#x77E5;&#x5FAE;&#x4FE1;&#x540E;&#x53F0;&#x7CFB;&#x7EDF;&#x4E0D;&#x518D;&#x53D1;&#x9001;&#x8BE5;&#x5355;&#x7684;&#x652F;&#x4ED8;&#x901A;&#x77E5;&#x3002;</li>
<li>11&#xFF09;&#x672A;&#x6536;&#x5230;&#x652F;&#x4ED8;&#x901A;&#x77E5;&#x7684;&#x60C5;&#x51B5;&#xFF0C;&#x5546;&#x6237;&#x540E;&#x53F0;&#x7CFB;&#x7EDF;&#x8C03;&#x7528;<a href="https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=9_2">&#x67E5;&#x8BE2;&#x8BA2;&#x5355;API</a></li>
<li>12&#xFF09;&#x5546;&#x6237;&#x786E;&#x8BA4;&#x8BA2;&#x5355;&#x5DF2;&#x652F;&#x4ED8;&#x540E;&#x7ED9;&#x7528;&#x6237;&#x53D1;&#x8D27;&#x3002;</li>
</ul>
<h2 id="t105.&#x7ED8;&#x5236;&#x9875;&#x9762;">5.&#x7ED8;&#x5236;&#x9875;&#x9762; <a href="#t105.&#x7ED8;&#x5236;&#x9875;&#x9762;"> # </a></h2>
<h3 id="t115.1 &#x751F;&#x6210;&#x9879;&#x76EE;">5.1 &#x751F;&#x6210;&#x9879;&#x76EE; <a href="#t115.1 &#x751F;&#x6210;&#x9879;&#x76EE;"> # </a></h3>
<pre><code class="lang-js">$ npm i egg-init -g
$ egg-init zhufeng-wxpay --type=simple
$ cd zhufeng-wxpay
$ npm i
$ npm run dev
$ open localhost:<span class="hljs-number">7001</span>

ssh -vnNT -R <span class="hljs-number">7689</span>:localhost:<span class="hljs-number">7001</span> <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8af8e5e5feca">[email&#160;protected]</a><span class="hljs-number">47.105</span><span class="hljs-number">.88</span><span class="hljs-number">.180</span>
</code></pre>
<h3 id="t125.2 &#x652F;&#x6301;&#x6A21;&#x7248;">5.2 &#x652F;&#x6301;&#x6A21;&#x7248; <a href="#t125.2 &#x652F;&#x6301;&#x6A21;&#x7248;"> # </a></h3>
<h4 id="t135.2.1 package.json">5.2.1 package.json <a href="#t135.2.1 package.json"> # </a></h4>
<pre><code class="lang-js">yarn add egg-view-ejs
</code></pre>
<h4 id="t145.2.2 app/controller/home.js">5.2.2 app/controller/home.js <a href="#t145.2.2 app/controller/home.js"> # </a></h4>
<p>app/controller/home.js</p>
<pre><code class="lang-diff">   async checkout() {
<span class="hljs-deletion">-      </span>
<span class="hljs-addition">+      const { ctx, app } = this;</span>
<span class="hljs-addition">+      await ctx.render(&apos;checkout&apos;);</span>
   }
 }
</code></pre>
<h4 id="t155.2.3 checkout.html">5.2.3 checkout.html <a href="#t155.2.3 checkout.html"> # </a></h4>
<p>app/view/checkout.html</p>
<pre><code class="lang-html"><span class="hljs-meta">&lt;!DOCTYPE html&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">html</span> <span class="hljs-attr">lang</span>=<span class="hljs-string">&quot;en&quot;</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">charset</span>=<span class="hljs-string">&quot;UTF-8&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;viewport&quot;</span> <span class="hljs-attr">content</span>=<span class="hljs-string">&quot;width=device-width, initial-scale=1.0&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">http-equiv</span>=<span class="hljs-string">&quot;X-UA-Compatible&quot;</span> <span class="hljs-attr">content</span>=<span class="hljs-string">&quot;ie=edge&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">link</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">&quot;stylesheet&quot;</span> <span class="hljs-attr">href</span>=<span class="hljs-string">&quot;https://cdn.bootcss.com/bootstrap/4.0.0/css/bootstrap.min.css&quot;</span> <span class="hljs-attr">integrity</span>=<span class="hljs-string">&quot;sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm&quot;</span> <span class="hljs-attr">crossorigin</span>=<span class="hljs-string">&quot;anonymous&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">src</span>=<span class="hljs-string">&quot;https://cdn.bootcss.com/jquery/3.2.1/jquery.slim.min.js&quot;</span> <span class="hljs-attr">integrity</span>=<span class="hljs-string">&quot;sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN&quot;</span> <span class="hljs-attr">crossorigin</span>=<span class="hljs-string">&quot;anonymous&quot;</span>&gt;</span><span class="undefined"></span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">src</span>=<span class="hljs-string">&quot;https://cdn.bootcss.com/popper.js/1.12.9/umd/popper.min.js&quot;</span> <span class="hljs-attr">integrity</span>=<span class="hljs-string">&quot;sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q&quot;</span> <span class="hljs-attr">crossorigin</span>=<span class="hljs-string">&quot;anonymous&quot;</span>&gt;</span><span class="undefined"></span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">src</span>=<span class="hljs-string">&quot;https://cdn.bootcss.com/bootstrap/4.0.0/js/bootstrap.min.js&quot;</span> <span class="hljs-attr">integrity</span>=<span class="hljs-string">&quot;sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl&quot;</span> <span class="hljs-attr">crossorigin</span>=<span class="hljs-string">&quot;anonymous&quot;</span>&gt;</span><span class="undefined"></span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>&#x5FAE;&#x4FE1;&#x652F;&#x4ED8;<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;container&quot;</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;row justify-content-center&quot;</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;col-4&quot;</span>&gt;</span>
                    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;card text-center mt-5&quot;</span>&gt;</span>
                        <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;card-header&quot;</span>&gt;</span>
                        <span class="hljs-tag">&lt;<span class="hljs-name">h3</span>&gt;</span>&#x5FAE;&#x4FE1;&#x652F;&#x4ED8;<span class="hljs-tag">&lt;/<span class="hljs-name">h3</span>&gt;</span>
                        <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
                        <span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">&quot;/public/images/qrcode.png&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;card-img-top&quot;</span>&gt;</span>
                        <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;card-body&quot;</span>&gt;</span>
                            <span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">&quot;/public/images/scan.png&quot;</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">&quot;&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;w-100&quot;</span>&gt;</span>
                        <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
                    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
                <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></pre>
<h4 id="t165.2.4 config.default.js">5.2.4 config.default.js <a href="#t165.2.4 config.default.js"> # </a></h4>
<p>config/config.default.js</p>
<pre><code class="lang-js">  config.view={
    <span class="hljs-attr">defaultViewEngine</span>: <span class="hljs-string">&apos;ejs&apos;</span>,
    <span class="hljs-attr">defaultExtension</span>:<span class="hljs-string">&apos;.html&apos;</span>,
    <span class="hljs-attr">mapping</span>: {
       <span class="hljs-string">&apos;.html&apos;</span>:<span class="hljs-string">&apos;ejs&apos;</span>
    } 
  }
</code></pre>
<h4 id="t175.2.5 plugin.js">5.2.5 plugin.js <a href="#t175.2.5 plugin.js"> # </a></h4>
<p>config/plugin.js</p>
<pre><code class="lang-js">exports.ejs = {
    <span class="hljs-attr">enable</span>: <span class="hljs-literal">true</span>,
    <span class="hljs-attr">package</span>: <span class="hljs-string">&apos;egg-view-ejs&apos;</span>,
};
</code></pre>
<h3 id="t185.3 &#x652F;&#x4ED8;&#x548C;&#x901A;&#x77E5;">5.3 &#x652F;&#x4ED8;&#x548C;&#x901A;&#x77E5; <a href="#t185.3 &#x652F;&#x4ED8;&#x548C;&#x901A;&#x77E5;"> # </a></h3>
<h4 id="t195.3.1 package.json">5.3.1 package.json <a href="#t195.3.1 package.json"> # </a></h4>
<pre><code class="lang-diff">   &quot;dependencies&quot;: {
<span class="hljs-addition">+    &quot;axios&quot;: &quot;^0.18.0&quot;,</span>
<span class="hljs-addition">+    &quot;moment&quot;: &quot;^2.22.2&quot;,</span>
<span class="hljs-addition">+    &quot;qrcode&quot;: &quot;^1.2.2&quot;,</span>
<span class="hljs-addition">+    &quot;randomstring&quot;: &quot;^1.1.5&quot;,</span>
<span class="hljs-addition">+    &quot;uuid&quot;: &quot;^3.3.2&quot;,</span>
<span class="hljs-addition">+    &quot;xml-js&quot;: &quot;^1.6.7&quot;</span>
   }
</code></pre>
<h4 id="t205.3.2 app/router.js">5.3.2 app/router.js <a href="#t205.3.2 app/router.js"> # </a></h4>
<p>app/router.js</p>
<pre><code class="lang-js">  router.post(<span class="hljs-string">&apos;/wxpay/notify&apos;</span>,controller.home.notify);
</code></pre>
<h4 id="t215.3.3 home.js">5.3.3 home.js <a href="#t215.3.3 home.js"> # </a></h4>
<p>app/controller/home.js</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> Controller = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;egg&apos;</span>).Controller;
<span class="hljs-keyword">const</span> moment = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;moment&apos;</span>);
<span class="hljs-keyword">const</span> randomstring = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;randomstring&apos;</span>);
<span class="hljs-keyword">const</span> querystring = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;querystring&apos;</span>);
<span class="hljs-keyword">const</span> crypto = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;crypto&apos;</span>);
<span class="hljs-keyword">const</span> xmljs = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;xml-js&apos;</span>);
<span class="hljs-keyword">const</span> axios = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;axios&apos;</span>);
<span class="hljs-keyword">const</span> qrcode = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;qrcode&apos;</span>);
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">HomeController</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Controller</span> </span>{
  <span class="hljs-keyword">async</span> index() {
    <span class="hljs-keyword">this</span>.ctx.body = <span class="hljs-string">&apos;hi, egg&apos;</span>;
  }
  wxSign(order, key,logger) {
    <span class="hljs-comment">//&#x5BF9;&#x53C2;&#x6570;&#x8FDB;&#x884C;&#x6392;&#x5E8F;  </span>
    <span class="hljs-keyword">let</span> sortedOrder = <span class="hljs-built_in">Object</span>.keys(order).sort().reduce(<span class="hljs-function">(<span class="hljs-params">memo, key</span>) =&gt;</span> {
      memo[key] = order[key];
      <span class="hljs-keyword">return</span> memo;
    }, {});
    logger.info(<span class="hljs-string">&apos;&#x6392;&#x8FC7;&#x5E8F;&#x7684;&#x8BA2;&#x5355;&apos;</span>, sortedOrder);
    <span class="hljs-comment">//&#x8F6C;&#x5316;&#x6210;&#x5B57;&#x7B26;&#x4E32;  </span>
    <span class="hljs-keyword">const</span> stringifiedOrder = querystring.stringify(sortedOrder, <span class="hljs-literal">null</span>, <span class="hljs-literal">null</span>, {
      <span class="hljs-attr">encodeURIComponent</span>: querystring.unescape
    });
    logger.info(<span class="hljs-string">&apos;&#x4E0D;&#x5E26;key&#x7684;&#x8BA2;&#x5355;&#x5B57;&#x7B26;&#x4E32;&apos;</span>, stringifiedOrder);
    <span class="hljs-comment">//&#x52A0;&#x4E0A;&#x5BC6;&#x94A5;  </span>
    <span class="hljs-keyword">const</span> stringifiedOrderWithKey = <span class="hljs-string">`<span class="hljs-subst">${stringifiedOrder}</span>&amp;key=<span class="hljs-subst">${key}</span>`</span>;
    logger.info(<span class="hljs-string">&apos;&#x5E26;key&#x7684;&#x8BA2;&#x5355;&#x5B57;&#x7B26;&#x4E32;&apos;</span>, stringifiedOrderWithKey);
    <span class="hljs-comment">//&#x8BA1;&#x7B97;&#x51FA;&#x7B7E;&#x540D;</span>
    <span class="hljs-keyword">const</span> sign = crypto.createHash(<span class="hljs-string">&apos;md5&apos;</span>).update(stringifiedOrderWithKey).digest(<span class="hljs-string">&apos;hex&apos;</span>).toUpperCase();
    <span class="hljs-keyword">return</span> sign;
  }
  <span class="hljs-keyword">async</span> checkout() {
    <span class="hljs-keyword">const</span> {
      ctx,
      app
    } = <span class="hljs-keyword">this</span>;
    <span class="hljs-keyword">const</span> {
      logger
    } = ctx;
    <span class="hljs-keyword">const</span> {
      wxpay = {}
    } = app.config;
    <span class="hljs-comment">//&#x516C;&#x4F17;&#x8D26;&#x53F7;ID</span>
    <span class="hljs-keyword">const</span> appid = wxpay.appid;
    <span class="hljs-comment">//&#x5546;&#x6237;&#x53F7;&#x7801; &#x5546;&#x6237;&#x5E73;&#x53F0;(https://pay.weixin.qq.com)-&gt;&#x4EA7;&#x54C1;&#x4E2D;&#x5FC3;-&gt;&#x5F00;&#x53D1;&#x914D;&#x7F6E;-&gt;&#x5546;&#x6237;&#x4FE1;&#x606F;-&gt;&#x5546;&#x6237;&#x53F7;</span>
    <span class="hljs-comment">//APPID&#x6388;&#x6743;&#x7BA1;&#x7406; &#x5546;&#x6237;&#x5E73;&#x53F0;(https://pay.weixin.qq.com)-&gt;&#x4EA7;&#x54C1;&#x4E2D;&#x5FC3;-&gt;&#x5F00;&#x53D1;&#x914D;&#x7F6E;-&gt;&#x5546;&#x6237;&#x4FE1;&#x606F;-&gt;&#x5546;&#x6237;&#x53F7;</span>
    <span class="hljs-keyword">const</span> mch_id = wxpay.mch_id;
    <span class="hljs-comment">//&#x56DE;&#x8C03;&#x901A;&#x77E5;url</span>
    <span class="hljs-keyword">const</span> notify_url = wxpay.notify_url;
    <span class="hljs-comment">//&#x5BC6;&#x94A5;</span>
    <span class="hljs-keyword">const</span> key = wxpay.key;
    <span class="hljs-comment">//&#x7EDF;&#x4E00;&#x4E0B;&#x5355;&#x63A5;&#x53E3;</span>
    <span class="hljs-keyword">const</span> unifiedorder = wxpay.unifiedorder;
    <span class="hljs-comment">//&#x5546;&#x6237;&#x8BA2;&#x5355;&#x53F7;</span>
    <span class="hljs-keyword">const</span> out_trade_no = moment().local().format(<span class="hljs-string">&apos;YYYYMMDDhhmmss&apos;</span>);
    <span class="hljs-comment">//&#x5546;&#x54C1;&#x63CF;&#x8FF0;</span>
    <span class="hljs-keyword">const</span> body = <span class="hljs-string">&apos;&#x73E0;&#x5CF0;&#x57F9;&#x8BAD;&apos;</span>;
    <span class="hljs-comment">//&#x5546;&#x54C1;&#x4EF7;&#x683C;</span>
    <span class="hljs-keyword">const</span> total_fee = <span class="hljs-number">1</span>;
    <span class="hljs-comment">//&#x652F;&#x4ED8;&#x7C7B;&#x578B;</span>
    <span class="hljs-keyword">const</span> trade_type = <span class="hljs-string">&apos;NATIVE&apos;</span>;
    <span class="hljs-comment">//&#x5546;&#x54C1;ID</span>
    <span class="hljs-keyword">const</span> product_id = <span class="hljs-number">100</span>;
    <span class="hljs-comment">//&#x968F;&#x673A;&#x5B57;&#x7B26;&#x4E32;</span>
    <span class="hljs-keyword">const</span> nonce_str = randomstring.generate(<span class="hljs-number">32</span>);
    <span class="hljs-comment">//&#x6784;&#x5EFA;&#x8BA2;&#x5355;  </span>
    <span class="hljs-keyword">let</span> order = {
      appid,
      mch_id,
      out_trade_no,
      body,
      total_fee,
      product_id,
      notify_url,
      nonce_str,
      trade_type
    }
    <span class="hljs-keyword">const</span> sign = <span class="hljs-keyword">this</span>.wxSign(order, key,logger);
    logger.info(<span class="hljs-string">&apos;&#x7B7E;&#x540D;&apos;</span>, sign);
    <span class="hljs-comment">//&#x8F6C;&#x6362;&#x6210;XML&#x683C;&#x5F0F;    </span>
    <span class="hljs-keyword">const</span> xmlOrder = xmljs.js2xml({
      <span class="hljs-attr">xml</span>: {
        ...order,
        sign
      }
    }, {
      <span class="hljs-attr">compact</span>: <span class="hljs-literal">true</span>
    });
    logger.info(<span class="hljs-string">&apos;XML&#x8BA2;&#x5355;&apos;</span>, xmlOrder);
    <span class="hljs-comment">//&#x8BF7;&#x6C42;&#x7EDF;&#x4E00;&#x4E0B;&#x5355;&#x63A5;&#x53E3;</span>
    <span class="hljs-keyword">const</span> unifiedorderResponse = <span class="hljs-keyword">await</span> axios.post(unifiedorder, xmlOrder);
    logger.info(<span class="hljs-string">&apos;&#x7EDF;&#x4E00;&#x4E0B;&#x5355;&#x54CD;&#x5E94;&apos;</span>, unifiedorderResponse.data);

    <span class="hljs-keyword">const</span> _prepay = xmljs.xml2js(unifiedorderResponse.data, {
      <span class="hljs-attr">compact</span>: <span class="hljs-literal">true</span>,
      <span class="hljs-attr">cdataKey</span>: <span class="hljs-string">&apos;value&apos;</span>,
      <span class="hljs-attr">textKey</span>:<span class="hljs-string">&apos;value&apos;</span>
    });
    logger.info(<span class="hljs-string">&apos;_prepay&apos;</span>, _prepay);

    <span class="hljs-keyword">const</span> prepay = <span class="hljs-built_in">Object</span>.entries(_prepay.xml).reduce(<span class="hljs-function">(<span class="hljs-params">memo, [key, value]</span>) =&gt;</span> {
      memo[key]=value.value;
      <span class="hljs-keyword">return</span> memo;
    }, {});

    logger.info(<span class="hljs-string">&apos;prepay&apos;</span>, prepay);
    <span class="hljs-keyword">const</span> {
      code_url
    } = prepay;
    <span class="hljs-keyword">const</span> qrcodeUrl = <span class="hljs-keyword">await</span> qrcode.toDataURL(code_url, {
      <span class="hljs-attr">width</span>: <span class="hljs-number">300</span>
    });
    <span class="hljs-keyword">await</span> ctx.render(<span class="hljs-string">&apos;checkout&apos;</span>, {
      qrcodeUrl
    });
  }
  parseXML(req) {
      <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Promise</span>(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">resolve,reject</span>)</span>{
          <span class="hljs-keyword">let</span> buffers = [];
          req.on(<span class="hljs-string">&apos;data&apos;</span>, <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">data</span>) </span>{
              buffers.push(data);
          });
          req.on(<span class="hljs-string">&apos;end&apos;</span>, <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
              <span class="hljs-keyword">let</span> ret = Buffer.concat(buffers);
              resolve(ret.toString());
          });
      });
  }
  <span class="hljs-keyword">async</span> notify() {
    <span class="hljs-keyword">const</span> {ctx,app} = <span class="hljs-keyword">this</span>;
      <span class="hljs-keyword">const</span> { logger } = ctx;
      <span class="hljs-keyword">const</span> {
        wxpay = {}
      } = app.config;
      <span class="hljs-keyword">const</span> key = wxpay.key;
    <span class="hljs-keyword">let</span> body = <span class="hljs-keyword">await</span> <span class="hljs-keyword">this</span>.parseXML(ctx.req);
    logger.debug(<span class="hljs-string">&apos;request&apos;</span>,body);  
    <span class="hljs-keyword">const</span> _payment = xmljs.xml2js(body, {
      <span class="hljs-attr">compact</span>: <span class="hljs-literal">true</span>,
      <span class="hljs-attr">cdataKey</span>: <span class="hljs-string">&apos;value&apos;</span>,
      <span class="hljs-attr">textKey</span>:<span class="hljs-string">&apos;value&apos;</span>
    });
    logger.info(<span class="hljs-string">&apos;_payment&apos;</span>, _payment);
    <span class="hljs-keyword">const</span> payment = <span class="hljs-built_in">Object</span>.entries(_payment.xml).reduce(<span class="hljs-function">(<span class="hljs-params">memo, [key, value]</span>) =&gt;</span> {
      memo[key] = value.value;
      <span class="hljs-keyword">return</span> memo;
    }, {});
    logger.info(<span class="hljs-string">&apos;payment&apos;</span>, payment);
    <span class="hljs-keyword">const</span> paymentSign = payment.sign;
    logger.debug(<span class="hljs-string">&apos;paymentSign&apos;</span>, paymentSign);
    <span class="hljs-keyword">delete</span> payment.sign;
    <span class="hljs-keyword">const</span> mySign = <span class="hljs-keyword">this</span>.wxSign(payment, key,logger);
    logger.debug(<span class="hljs-string">&apos;mySign&apos;</span>, mySign);
    <span class="hljs-keyword">const</span> return_code = paymentSign === mySign ? <span class="hljs-string">&apos;SUCCESS&apos;</span> : <span class="hljs-string">&quot;FAIL&quot;</span>;
    <span class="hljs-keyword">const</span> reply = {
      <span class="hljs-attr">xml</span>: {
        return_code
      }
    }
    <span class="hljs-keyword">const</span> ret = xmljs.js2xml(reply, {
      <span class="hljs-attr">compact</span>: <span class="hljs-literal">true</span>
    });
    logger.debug(<span class="hljs-string">&apos;&#x901A;&#x77E5;&#x8FD4;&#x56DE;&apos;</span>, ret);
    ctx.body = ret;
  }
}

<span class="hljs-built_in">module</span>.exports = HomeController;
</code></pre>
<h4 id="t225.3.4 checkout.html">5.3.4 checkout.html <a href="#t225.3.4 checkout.html"> # </a></h4>
<p>app/view/checkout.html</p>
<pre><code class="lang-diff"><span class="hljs-deletion">-    &lt;img src=&quot;/public/images/qrcode.png&quot; class=&quot;card-img-top&quot;&gt;</span>
<span class="hljs-addition">+    &lt;img src=&quot;&lt;%=qrcodeUrl%&gt;&quot; class=&quot;card-img-top&quot;&gt;</span>
</code></pre>
<h4 id="t235.3.5 config.default.js">5.3.5 config.default.js <a href="#t235.3.5 config.default.js"> # </a></h4>
<p>config/config.default.js</p>
<pre><code class="lang-js">  config.logger={
    <span class="hljs-attr">level</span>: <span class="hljs-string">&apos;DEBUG&apos;</span>,
    <span class="hljs-attr">allowDebugAtProd</span>: <span class="hljs-literal">true</span>,
    <span class="hljs-attr">consoleLevel</span>: <span class="hljs-string">&apos;DEBUG&apos;</span>
  }
  exports.security = {
    <span class="hljs-attr">csrf</span>: {
      <span class="hljs-attr">enable</span>: <span class="hljs-literal">false</span>,
      <span class="hljs-attr">ignoreJSON</span>: <span class="hljs-literal">true</span>
    }
  };
  config.wxpay={
    <span class="hljs-attr">appid</span>: <span class="hljs-string">&apos;&apos;</span>,
    <span class="hljs-attr">mch_id</span>: <span class="hljs-string">&apos;&apos;</span>,
    <span class="hljs-attr">key</span>: <span class="hljs-string">&apos;&apos;</span>,
    <span class="hljs-attr">notify_url</span>: <span class="hljs-string">&apos;http://front.zhufengpeixun.cn/wxpay/notify&apos;</span>,
    <span class="hljs-attr">unifiedorder</span>:<span class="hljs-string">&apos;https://api.mch.weixin.qq.com/pay/unifiedorder&apos;</span>
  }
</code></pre>
<h3 id="t245.4 &#x67E5;&#x8BE2;&#x7ED3;&#x679C;">5.4 &#x67E5;&#x8BE2;&#x7ED3;&#x679C; <a href="#t245.4 &#x67E5;&#x8BE2;&#x7ED3;&#x679C;"> # </a></h3>
<h4 id="t255.4.1 app/router.js">5.4.1 app/router.js <a href="#t255.4.1 app/router.js"> # </a></h4>
<pre><code class="lang-js">router.get(<span class="hljs-string">&apos;/wxpay/query&apos;</span>,controller.home.query);
</code></pre>
<h4 id="t265.4.2 result.html">5.4.2 result.html <a href="#t265.4.2 result.html"> # </a></h4>
<p>app/view/result.html</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;container&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;jumbotron mt-5 text-center&quot;</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">%=trade_state_desc%</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
</code></pre>
<h4 id="t275.4.3 config.default.js">5.4.3 config.default.js <a href="#t275.4.3 config.default.js"> # </a></h4>
<p>config/config.default.js</p>
<pre><code class="lang-html">+    unifiedorder: &apos;https://api.mch.weixin.qq.com/pay/unifiedorder&apos;,
+    orderquery:&apos;https://api.mch.weixin.qq.com/pay/orderquery&apos;
</code></pre>
<h4 id="t285.4.4 app/controller/home.js">5.4.4 app/controller/home.js <a href="#t285.4.4 app/controller/home.js"> # </a></h4>
<p>home.js</p>
<pre><code class="lang-js"><span class="hljs-meta">&apos;use strict&apos;</span>;

<span class="hljs-keyword">const</span> Controller = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;egg&apos;</span>).Controller;
<span class="hljs-keyword">const</span> moment = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;moment&apos;</span>);
<span class="hljs-keyword">const</span> randomstring = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;randomstring&apos;</span>);
<span class="hljs-keyword">const</span> querystring = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;querystring&apos;</span>);
<span class="hljs-keyword">const</span> crypto = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;crypto&apos;</span>);
<span class="hljs-keyword">const</span> transformer = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;xml-js&apos;</span>);
<span class="hljs-keyword">const</span> axios = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;axios&apos;</span>);
<span class="hljs-keyword">const</span> qrcode = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;qrcode&apos;</span>);
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">HomeController</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Controller</span> </span>{
  <span class="hljs-keyword">async</span> index() {
    <span class="hljs-keyword">this</span>.ctx.body = <span class="hljs-string">&apos;hi, egg&apos;</span>;
  }
  wxSign(order, key,logger) {
    <span class="hljs-comment">//&#x5BF9;&#x53C2;&#x6570;&#x8FDB;&#x884C;&#x6392;&#x5E8F;  </span>
    <span class="hljs-keyword">let</span> sortedOrder = <span class="hljs-built_in">Object</span>.keys(order).sort().reduce(<span class="hljs-function">(<span class="hljs-params">memo, key</span>) =&gt;</span> {
      memo[key] = order[key];
      <span class="hljs-keyword">return</span> memo;
    }, {});
    logger.info(<span class="hljs-string">&apos;&#x6392;&#x8FC7;&#x5E8F;&#x7684;&#x8BA2;&#x5355;&apos;</span>, sortedOrder);
    <span class="hljs-comment">//&#x8F6C;&#x5316;&#x6210;&#x5B57;&#x7B26;&#x4E32;  </span>
    <span class="hljs-keyword">const</span> stringifiedOrder = querystring.stringify(sortedOrder, <span class="hljs-literal">null</span>, <span class="hljs-literal">null</span>, {
      <span class="hljs-attr">encodeURIComponent</span>: querystring.unescape
    });
    logger.info(<span class="hljs-string">&apos;&#x4E0D;&#x5E26;key&#x7684;&#x8BA2;&#x5355;&#x5B57;&#x7B26;&#x4E32;&apos;</span>, stringifiedOrder);
    <span class="hljs-comment">//&#x52A0;&#x4E0A;&#x5BC6;&#x94A5;  </span>
    <span class="hljs-keyword">const</span> stringifiedOrderWithKey = <span class="hljs-string">`<span class="hljs-subst">${stringifiedOrder}</span>&amp;key=<span class="hljs-subst">${key}</span>`</span>;
    logger.info(<span class="hljs-string">&apos;&#x5E26;key&#x7684;&#x8BA2;&#x5355;&#x5B57;&#x7B26;&#x4E32;&apos;</span>, stringifiedOrderWithKey);
    <span class="hljs-comment">//&#x8BA1;&#x7B97;&#x51FA;&#x7B7E;&#x540D;</span>
    <span class="hljs-keyword">const</span> sign = crypto.createHash(<span class="hljs-string">&apos;md5&apos;</span>).update(stringifiedOrderWithKey).digest(<span class="hljs-string">&apos;hex&apos;</span>).toUpperCase();
    <span class="hljs-keyword">return</span> sign;
  }
  xml2js(data,logger) {
    <span class="hljs-keyword">const</span> _result = transformer.xml2js(data, {
      <span class="hljs-attr">compact</span>: <span class="hljs-literal">true</span>,
      <span class="hljs-attr">cdataKey</span>: <span class="hljs-string">&apos;value&apos;</span>,
      <span class="hljs-attr">textKey</span>:<span class="hljs-string">&apos;value&apos;</span>
    });
    logger.info(<span class="hljs-string">&apos;_result&apos;</span>, _result);

    <span class="hljs-keyword">const</span> result = <span class="hljs-built_in">Object</span>.entries(_result.xml).reduce(<span class="hljs-function">(<span class="hljs-params">memo, [key, value]</span>) =&gt;</span> {
      memo[key]=value.value;
      <span class="hljs-keyword">return</span> memo;
    },{});
    logger.info(<span class="hljs-string">&apos;result&apos;</span>, result);
    <span class="hljs-keyword">return</span> result;
  }
  <span class="hljs-keyword">async</span> checkout() {
    <span class="hljs-keyword">const</span> {
      ctx,
      app
    } = <span class="hljs-keyword">this</span>;
    <span class="hljs-keyword">const</span> {
      logger
    } = ctx;
    <span class="hljs-keyword">const</span> {
      wxpay = {}
    } = app.config;
    <span class="hljs-comment">//&#x516C;&#x4F17;&#x8D26;&#x53F7;ID</span>
    <span class="hljs-keyword">const</span> appid = wxpay.appid;
    <span class="hljs-comment">//&#x5546;&#x6237;&#x53F7;&#x7801; &#x5546;&#x6237;&#x5E73;&#x53F0;(https://pay.weixin.qq.com)-&gt;&#x4EA7;&#x54C1;&#x4E2D;&#x5FC3;-&gt;&#x5F00;&#x53D1;&#x914D;&#x7F6E;-&gt;&#x5546;&#x6237;&#x4FE1;&#x606F;-&gt;&#x5546;&#x6237;&#x53F7;</span>
    <span class="hljs-comment">//APPID&#x6388;&#x6743;&#x7BA1;&#x7406; &#x5546;&#x6237;&#x5E73;&#x53F0;(https://pay.weixin.qq.com)-&gt;&#x4EA7;&#x54C1;&#x4E2D;&#x5FC3;-&gt;&#x5F00;&#x53D1;&#x914D;&#x7F6E;-&gt;&#x5546;&#x6237;&#x4FE1;&#x606F;-&gt;&#x5546;&#x6237;&#x53F7;</span>
    <span class="hljs-keyword">const</span> mch_id = wxpay.mch_id;
    <span class="hljs-comment">//&#x56DE;&#x8C03;&#x901A;&#x77E5;url</span>
    <span class="hljs-keyword">const</span> notify_url = wxpay.notify_url;
    <span class="hljs-comment">//&#x5BC6;&#x94A5;</span>
    <span class="hljs-keyword">const</span> key = wxpay.key;
    <span class="hljs-comment">//&#x7EDF;&#x4E00;&#x4E0B;&#x5355;&#x63A5;&#x53E3;</span>
    <span class="hljs-keyword">const</span> unifiedorder = wxpay.unifiedorder;
    <span class="hljs-comment">//&#x5546;&#x6237;&#x8BA2;&#x5355;&#x53F7;</span>
    <span class="hljs-keyword">const</span> out_trade_no=moment().local().format(<span class="hljs-string">&apos;YYYYMMDDhhmmss&apos;</span>);
    ctx.session.out_trade_no=out_trade_no;
    <span class="hljs-comment">//&#x5546;&#x54C1;&#x63CF;&#x8FF0;</span>
    <span class="hljs-keyword">const</span> body = <span class="hljs-string">&apos;&#x73E0;&#x5CF0;&#x57F9;&#x8BAD;&apos;</span>;
    <span class="hljs-comment">//&#x5546;&#x54C1;&#x4EF7;&#x683C;</span>
    <span class="hljs-keyword">const</span> total_fee = <span class="hljs-number">1</span>;
    <span class="hljs-comment">//&#x652F;&#x4ED8;&#x7C7B;&#x578B;</span>
    <span class="hljs-keyword">const</span> trade_type = <span class="hljs-string">&apos;NATIVE&apos;</span>;
    <span class="hljs-comment">//&#x5546;&#x54C1;ID</span>
    <span class="hljs-keyword">const</span> product_id = <span class="hljs-number">100</span>;
    <span class="hljs-comment">//&#x968F;&#x673A;&#x5B57;&#x7B26;&#x4E32;</span>
    <span class="hljs-keyword">const</span> nonce_str = randomstring.generate(<span class="hljs-number">32</span>);
    <span class="hljs-comment">//&#x6784;&#x5EFA;&#x8BA2;&#x5355;  </span>
    <span class="hljs-keyword">let</span> order = {
      appid,
      mch_id,
      out_trade_no,
      body,
      total_fee,
      product_id,
      notify_url,
      nonce_str,
      trade_type
    }
    <span class="hljs-keyword">const</span> sign = <span class="hljs-keyword">this</span>.wxSign(order, key,logger);
    logger.info(<span class="hljs-string">&apos;&#x7B7E;&#x540D;&apos;</span>, sign);
    <span class="hljs-comment">//&#x8F6C;&#x6362;&#x6210;XML&#x683C;&#x5F0F;    </span>
    <span class="hljs-keyword">const</span> xmlOrder = transformer.js2xml({
      <span class="hljs-attr">xml</span>: {
        ...order,
        sign
      }
    }, {
      <span class="hljs-attr">compact</span>: <span class="hljs-literal">true</span>
    });
    logger.info(<span class="hljs-string">&apos;XML&#x8BA2;&#x5355;&apos;</span>, xmlOrder);
    <span class="hljs-comment">//&#x8BF7;&#x6C42;&#x7EDF;&#x4E00;&#x4E0B;&#x5355;&#x63A5;&#x53E3;</span>
    <span class="hljs-keyword">const</span> unifiedorderResponse = <span class="hljs-keyword">await</span> axios.post(unifiedorder, xmlOrder);
    logger.info(<span class="hljs-string">&apos;&#x7EDF;&#x4E00;&#x4E0B;&#x5355;&#x54CD;&#x5E94;&apos;</span>, unifiedorderResponse.data);
    <span class="hljs-keyword">const</span> prepay=<span class="hljs-keyword">this</span>.xml2js(unifiedorderResponse.data,logger);
    logger.info(<span class="hljs-string">&apos;prepay&apos;</span>, prepay);
    <span class="hljs-keyword">const</span> {
      code_url
    } = prepay;
    <span class="hljs-keyword">const</span> qrcodeUrl = <span class="hljs-keyword">await</span> qrcode.toDataURL(code_url, {
      <span class="hljs-attr">width</span>: <span class="hljs-number">300</span>
    });
    <span class="hljs-keyword">await</span> ctx.render(<span class="hljs-string">&apos;checkout&apos;</span>, {
      qrcodeUrl
    });
  }
  parseXML(req) {
      <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Promise</span>(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">resolve,reject</span>)</span>{
          <span class="hljs-keyword">let</span> buffers = [];
          req.on(<span class="hljs-string">&apos;data&apos;</span>, <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">data</span>) </span>{
              buffers.push(data);
          });
          req.on(<span class="hljs-string">&apos;end&apos;</span>, <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
              <span class="hljs-keyword">let</span> ret = Buffer.concat(buffers);
              resolve(ret.toString());
          });
      });
  }
  <span class="hljs-keyword">async</span> notify() {
    <span class="hljs-keyword">const</span> {ctx,app} = <span class="hljs-keyword">this</span>;
      <span class="hljs-keyword">const</span> { logger } = ctx;
      <span class="hljs-keyword">const</span> {
        wxpay = {}
      } = app.config;
      <span class="hljs-keyword">const</span> key = wxpay.key;
    <span class="hljs-keyword">let</span> body = <span class="hljs-keyword">await</span> <span class="hljs-keyword">this</span>.parseXML(ctx.req);
    logger.debug(<span class="hljs-string">&apos;request&apos;</span>,body);  
    <span class="hljs-keyword">const</span> payment=<span class="hljs-keyword">this</span>.xml2js(body,logger);
    logger.info(<span class="hljs-string">&apos;payment&apos;</span>, payment);
    <span class="hljs-keyword">const</span> paymentSign = payment.sign;
    logger.debug(<span class="hljs-string">&apos;paymentSign&apos;</span>, paymentSign);
    <span class="hljs-keyword">delete</span> payment.sign;
    <span class="hljs-keyword">const</span> mySign = <span class="hljs-keyword">this</span>.wxSign(payment, key,logger);
    logger.debug(<span class="hljs-string">&apos;mySign&apos;</span>, mySign);
    <span class="hljs-keyword">const</span> return_code = paymentSign === mySign ? <span class="hljs-string">&apos;SUCCESS&apos;</span> : <span class="hljs-string">&quot;FAIL&quot;</span>;
    <span class="hljs-keyword">const</span> reply = {
      <span class="hljs-attr">xml</span>: {
        return_code
      }
    }
    <span class="hljs-keyword">const</span> ret = transformer.js2xml(reply, {
      <span class="hljs-attr">compact</span>: <span class="hljs-literal">true</span>
    });
    logger.debug(<span class="hljs-string">&apos;&#x901A;&#x77E5;&#x8FD4;&#x56DE;&apos;</span>, ret);
    ctx.body = ret;
  }

  <span class="hljs-keyword">async</span> query() {
    <span class="hljs-keyword">const</span> {
      ctx,
      app
    } = <span class="hljs-keyword">this</span>;
    <span class="hljs-keyword">const</span> {
      logger
    } = ctx;
    <span class="hljs-keyword">const</span> {
      wxpay = {}
    } = app.config;
    <span class="hljs-comment">//&#x516C;&#x4F17;&#x8D26;&#x53F7;ID</span>
    <span class="hljs-keyword">const</span> appid = wxpay.appid;
    <span class="hljs-comment">//&#x5546;&#x6237;&#x53F7;&#x7801; </span>
    <span class="hljs-keyword">const</span> mch_id = wxpay.mch_id;
    <span class="hljs-comment">//&#x5BC6;&#x94A5;</span>
    <span class="hljs-keyword">const</span> key = wxpay.key;
    <span class="hljs-comment">//&#x7EDF;&#x4E00;&#x4E0B;&#x5355;&#x63A5;&#x53E3;</span>
    <span class="hljs-keyword">const</span> orderquery=wxpay.orderquery;
    <span class="hljs-comment">//&#x968F;&#x673A;&#x5B57;&#x7B26;&#x4E32;</span>
    <span class="hljs-keyword">const</span> nonce_str = randomstring.generate(<span class="hljs-number">32</span>);
    <span class="hljs-keyword">let</span> query={
      appid,
      mch_id,
      <span class="hljs-attr">out_trade_no</span>: ctx.session.out_trade_no,
      nonce_str
    }

    <span class="hljs-keyword">let</span> sign=<span class="hljs-keyword">this</span>.wxSign(query,key,logger);
    logger.info(<span class="hljs-string">&apos;&#x7B7E;&#x540D;&apos;</span>, sign);
    <span class="hljs-comment">//&#x8F6C;&#x6362;&#x6210;XML&#x683C;&#x5F0F;    </span>
    <span class="hljs-keyword">const</span> xmlQuery = transformer.js2xml({
      <span class="hljs-attr">xml</span>: {
        ...query,
        sign
      }
    }, {
      <span class="hljs-attr">compact</span>: <span class="hljs-literal">true</span>
    });
    logger.info(<span class="hljs-string">&apos;XML&#x67E5;&#x8BE2;&#x6761;&#x4EF6;&apos;</span>, xmlQuery);
    <span class="hljs-comment">//&#x8BF7;&#x6C42;&#x7EDF;&#x4E00;&#x4E0B;&#x5355;&#x63A5;&#x53E3;</span>
    <span class="hljs-keyword">const</span> orderqueryResponse = <span class="hljs-keyword">await</span> axios.post(orderquery, xmlQuery);
    logger.info(<span class="hljs-string">&apos;&#x8BA2;&#x5355;&#x67E5;&#x8BE2;&#x54CD;&#x5E94;&apos;</span>,orderqueryResponse.data);
    <span class="hljs-keyword">const</span> queryResult =<span class="hljs-keyword">this</span>.xml2js(orderqueryResponse.data,logger);
    logger.info(<span class="hljs-string">&apos;queryResult&apos;</span>,queryResult);
    <span class="hljs-keyword">await</span> ctx.render(<span class="hljs-string">&apos;result&apos;</span>,queryResult);
  }
}
<span class="hljs-built_in">module</span>.exports = HomeController;
</code></pre>
<h2 id="t29&#x53C2;&#x8003;&#x8D44;&#x6599;">&#x53C2;&#x8003;&#x8D44;&#x6599; <a href="#t29&#x53C2;&#x8003;&#x8D44;&#x6599;"> # </a></h2>
<ul>
<li><a href="http://kf.qq.com/faq/170116AziqYV1701162eyAzA.html">&#x626B;&#x7801;&#x652F;&#x4ED8;&#x63A5;&#x5165;&#x65B9;&#x6CD5;&#x6307;&#x5F15;</a></li>
<li><a href="https://pay.weixin.qq.com">&#x767B;&#x5F55;&#x5FAE;&#x4FE1;&#x652F;&#x4ED8;</a></li>
<li><a href="https://pay.weixin.qq.com/wiki/doc/api/index.html">&#x5FAE;&#x4FE1;&#x652F;&#x4ED8;WIKI</a></li>
<li><a href="http://kf.qq.com/product/weixinmp.html">&#x5FAE;&#x4FE1;&#x5E2E;&#x52A9;&#x6587;&#x6863;</a></li>
<li><a href="https://mp.weixin.qq.com">&#x767B;&#x5F55;&#x5FAE;&#x4FE1;&#x516C;&#x4F17;&#x8D26;&#x53F7;</a></li>
<li><a href="https://jz.fkw.com/blog/660">&#x5FAE;&#x4FE1;&#x652F;&#x4ED8;&#x63A5;&#x5165;&#x6559;&#x7A0B;</a></li>
<li><a href="https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=9_1">&#x7EDF;&#x4E00;&#x4E0B;&#x5355;API</a></li>
<li><a href="https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=9_2">&#x67E5;&#x8BE2;&#x8BA2;&#x5355;API</a></li>
<li><a href="https://www.npmjs.com/package/xml-js">xml-js</a></li>
</ul>

        <div class="copyright">Powered by <a href="https://github.com/jaywcjlove/idoc" target="_blank">idoc</a>. Dependence <a href="https://nodejs.org">Node.js</a> run.</div>
    </div>
    
</div>

<script data-cfasync="false" src="/cdn-cgi/scripts/5c5dd728/cloudflare-static/email-decode.min.js"></script><script src="https://cdn.bootcss.com/jquery/3.0.0/jquery.js"></script>
<script>
$('.warpper .page-toc ul ul li a').on('click',function(){
  $('.warpper .page-toc ul ul li a').removeClass('my-active')
  $(this).addClass('my-active')
})
  // if (!$('.understand-me').length) {
  //   var bar = $(window).height() - $('.navbar ').height() - $('.page-toc').position().top;
  //   var count = bar / 26 / 2;
  //   var barHeight = $('.page-toc').outerHeight();
  //   $('.page-toc li').eq(0).children('a').addClass('red');
  //   var arr = [];
  //   $("h1,h2,h3,h4,h5,h6").each(function () {
  //     arr.push($(this).position().top);
  //   });
  //   var timer
  //   function dark() {
  //     clearTimeout(timer)
  //      timer = setTimeout(function () {
  //      var top = Math.abs($('.page-toc > ul').position().top);
  //      var cur = $('.content').scrollTop();
  //      for (var i = arr.length; i >= 0; i--) {
  //        if (arr[i] <= cur) {
  //          break;
  //        }
  //      }
  //      if (i === -1) {
  //        i = 0;
  //      }
  //      $('.page-toc li a').removeClass('red');
  //      $('.page-toc li').eq(i).children('a').addClass('red');
  //      let height = $('.page-toc li').eq(i).position().top-$('.page-toc').height(); // 如果当前的offset出去了 回到中间可好？
  //      $('.page-toc').scrollTop(height+$('.page-toc').height()/2);
  //    },200)
  //   }

  //   $('.content').on('scroll', dark);
  // }
</script>
<style>

    /* ::-webkit-scrollbar{width:14px;}
    ::-webkit-scrollbar-track{background-color:transparent;}
    ::-webkit-scrollbar-thumb{background-color:transparent;}
    ::-webkit-scrollbar-thumb:hover {background-color:transparent}
    ::-webkit-scrollbar-thumb:active {background-color:transparent} */

    .page-toc > ul .red {
        background: #f3f3f3;
        z-index: 1;
        border-left: 3px solid #009a61;
        -webkit-transition: all .2s ease;
        transition: all .2s ease;
        color: #000
    }





</style>
</body>
</html>
